﻿using Module_Debug.Hardware;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;


namespace Module_Debug.Visionox_Gamma
{
    public partial class RM67120_Gamma : Form
    {
        CaSDK CaSDKObj = new CaSDK();
        CRC16 CRCData = new CRC16();

        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke 

        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过

        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色
        private double D_x, D_y;
        private double lum_off, x_off, y_off;
        private int index = 0;
        private int flag1 = 1; //lum
        private int flag2 = 1; //x
        private int flag3 = 1; //y
        private byte[] Send_buf = new byte[1];
        private byte[] Rec_tmp = new byte[1];
        private string adjust_class = null;
        private int adjust_num = 0;
        private static bool Gamma_adjust_timeout_flag = false;
        private int adjust_Rnum = 0;
        private int adjust_Gnum = 0;
        private int adjust_Bnum = 0;
        private int adjust_l = 0;
        private int adjust_x = 0;
        private int adjust_y = 0;
        private int step_l = 1;
        //private int step_m = 5;
        private int step_h = 12;

        private int[] Parttern_RM67120 = new int[25] { 255, 254, 252, 250, 248, 244, 240, 232, 224, 208, 192, 160, 128, 127, 95, 63, 47, 31, 23, 15, 11, 7, 5, 3, 1 };
        //监听RM67120挂载
        frmMain frmHelp = null;
        public RM67120_Gamma(frmMain RM67120)
        {
            frmHelp = RM67120;
            InitializeComponent();
            frmHelp.Child_window_hide_already = true;
            frmHelp.Child_Gamma_Window_Open_Enable = false;//防止重复开启子窗体   
        }
        //RM67120 监听卸载
        private void RM67120_Gamma_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(RM67120_DataReceived);
            frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);

            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM67120_Gamma_FormClosed！\r\n";
            frmHelp.Child_Gamma_Window_Open_Enable = true; //允许其他子窗体打开
            frmHelp.Child_window_hide_already = false;
            frmHelp.IC_comboBox.Enabled = true;
        }
        private void RM67120_Gamma_VisibleChanged(object sender, EventArgs e)
        {
            if (frmHelp.Child_window_hide_already == false) //子窗体已开启标识
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(RM67120_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM67120_Gamma_FormHide！\r\n";
                frmHelp.Child_window_hide_already = true; //子窗体已隐藏标识
            }
            else
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(RM67120_DataReceived);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM67120_Gamma_FormOpened！\r\n";
                frmHelp.Child_window_hide_already = false; //子窗体已开启标识
            }
        }

        //串口接收
        private void RM67120_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            if (IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = frmHelp.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                frmHelp.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    // 0x08: RM67120的Gamma读写、寄存器读写、OTP读写    设置  返回
                    if (buffer[0] == 0x08 && Setting.TempRecord.cmdLen > 0)
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }

                        }
                    }
                    else
                    {
                        buffer.RemoveRange(0, buffer.Count);
                    }
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        frmHelp.T1.Enabled = false; //停止超时计数
                        if (Rec_tmp[0] == 0x08)  //RM67120
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写寄存器\tOK！\r\n";
                                    }
                                    break;
                                case 0x08:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                        {
                                            if (Rec_tmp[3] == 0x00)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t写 OK！\r\n";
                                            else if (Rec_tmp[3] == 0x42)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t写 OK！\r\n";
                                            else if (Rec_tmp[3] == 0x81)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t写 OK！\r\n";
                                        }
                                    }
                                    break;

                                case 0x0A:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写OTP\t写 OK！\r\n";
                                    }
                                    break;
                                case 0x0C:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写OTP\t写 OK！\r\n";
                                    }
                                    break;
                                case 0x0B:
                                    {
                                        if (Setting.TempRecord.RM67120CmdType == 0x01)  //读OTP烧录次数
                                        {
                                            string tmp = "";
                                            tmp = String.Format("{0:X2}", Rec_tmp[4]);
                                            RM67120_OTP_Time.Text = tmp;

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x02:
                                    {
                                        if (Setting.TempRecord.RM67120CmdType == 0x02)  //register read
                                        {
                                            string tmp = "";
                                            for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                            {
                                                tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                            }
                                            tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                            txtRegData.Text = tmp;
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "寄存器\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x09:
                                    {
                                        if (Setting.TempRecord.RM67120CmdType == 0x03)  // red
                                        {
                                            RM67120_R0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            RM67120_R1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            RM67120_R3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            RM67120_R5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            RM67120_R7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            RM67120_R11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            RM67120_R15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            RM67120_R23.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            RM67120_R31.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            RM67120_R47.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            RM67120_R63.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            RM67120_R95.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            RM67120_R127.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            RM67120_R128.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            RM67120_R160.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            RM67120_R192.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            RM67120_R208.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            RM67120_R224.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            RM67120_R232.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            RM67120_R240.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            RM67120_R244.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            RM67120_R248.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            RM67120_R250.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            RM67120_R252.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            RM67120_R254.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            RM67120_R255.Value = Decimal.Parse((Rec_tmp[54] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.RM67120CmdType == 0x04)  // green
                                        {
                                            RM67120_G0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            RM67120_G1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            RM67120_G3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            RM67120_G5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            RM67120_G7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            RM67120_G11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            RM67120_G15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            RM67120_G23.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            RM67120_G31.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            RM67120_G47.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            RM67120_G63.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            RM67120_G95.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            RM67120_G127.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            RM67120_G128.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            RM67120_G160.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            RM67120_G192.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            RM67120_G208.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            RM67120_G224.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            RM67120_G232.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            RM67120_G240.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            RM67120_G244.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            RM67120_G248.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            RM67120_G250.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            RM67120_G252.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            RM67120_G254.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            RM67120_G255.Value = Decimal.Parse((Rec_tmp[54] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.RM67120CmdType == 0x05)  // blue
                                        {
                                            RM67120_B0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            RM67120_B1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            RM67120_B3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            RM67120_B5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            RM67120_B7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            RM67120_B11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            RM67120_B15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            RM67120_B23.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            RM67120_B31.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            RM67120_B47.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            RM67120_B63.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            RM67120_B95.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            RM67120_B127.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            RM67120_B128.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            RM67120_B160.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            RM67120_B192.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            RM67120_B208.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            RM67120_B224.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            RM67120_B232.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            RM67120_B240.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            RM67120_B244.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            RM67120_B248.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            RM67120_B250.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            RM67120_B252.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            RM67120_B254.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            RM67120_B255.Value = Decimal.Parse((Rec_tmp[54] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                            }
                        }
                        frmHelp.textBox1.SelectionStart = this.frmHelp.textBox1.Text.Length;
                        frmHelp.textBox1.ScrollToCaret();//滚动到光标处
                        if (frmHelp.textBox1.Lines.Length > 50) frmHelp.textBox1.Text = null;
                    }));
                }
            }
            finally
            {
                Listening = false;
            }
        }
        //Gamma保存
        private void RM67120_SaveGamma_Click(object sender, EventArgs e)
        {

        } //
        //Gamma载入
        private void RM67120_LoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
                string[] arrtmp = strtmp.Split(new Char[] { ',' });
                RM67120_R0.Text = arrtmp[1].ToString(); RM67120_G0.Text = arrtmp[3].ToString(); RM67120_B0.Text = arrtmp[5].ToString();
                RM67120_R1.Text = arrtmp[7].ToString(); RM67120_G1.Text = arrtmp[9].ToString(); RM67120_B1.Text = arrtmp[11].ToString();
                RM67120_R3.Text = arrtmp[13].ToString(); RM67120_G3.Text = arrtmp[15].ToString(); RM67120_B3.Text = arrtmp[17].ToString();
                RM67120_R5.Text = arrtmp[19].ToString(); RM67120_G5.Text = arrtmp[21].ToString(); RM67120_B5.Text = arrtmp[23].ToString();
                RM67120_R7.Text = arrtmp[25].ToString(); RM67120_G7.Text = arrtmp[27].ToString(); RM67120_B7.Text = arrtmp[29].ToString();
                RM67120_R11.Text = arrtmp[31].ToString(); RM67120_G11.Text = arrtmp[33].ToString(); RM67120_B11.Text = arrtmp[35].ToString();
                RM67120_R15.Text = arrtmp[37].ToString(); RM67120_G15.Text = arrtmp[39].ToString(); RM67120_B15.Text = arrtmp[41].ToString();
                RM67120_R23.Text = arrtmp[43].ToString(); RM67120_G23.Text = arrtmp[45].ToString(); RM67120_B23.Text = arrtmp[47].ToString();
                RM67120_R31.Text = arrtmp[49].ToString(); RM67120_G31.Text = arrtmp[51].ToString(); RM67120_B31.Text = arrtmp[53].ToString();
                RM67120_R47.Text = arrtmp[55].ToString(); RM67120_G47.Text = arrtmp[57].ToString(); RM67120_B47.Text = arrtmp[59].ToString();
                RM67120_R63.Text = arrtmp[61].ToString(); RM67120_G63.Text = arrtmp[63].ToString(); RM67120_B63.Text = arrtmp[65].ToString();
                RM67120_R95.Text = arrtmp[67].ToString(); RM67120_G95.Text = arrtmp[69].ToString(); RM67120_B95.Text = arrtmp[71].ToString();
                RM67120_R127.Text = arrtmp[73].ToString(); RM67120_G127.Text = arrtmp[75].ToString(); RM67120_B127.Text = arrtmp[77].ToString();
                RM67120_R128.Text = arrtmp[79].ToString(); RM67120_G128.Text = arrtmp[81].ToString(); RM67120_B128.Text = arrtmp[83].ToString();
                RM67120_R160.Text = arrtmp[85].ToString(); RM67120_G160.Text = arrtmp[87].ToString(); RM67120_B160.Text = arrtmp[89].ToString();
                RM67120_R192.Text = arrtmp[91].ToString(); RM67120_G192.Text = arrtmp[93].ToString(); RM67120_B192.Text = arrtmp[95].ToString();
                RM67120_R208.Text = arrtmp[97].ToString(); RM67120_G208.Text = arrtmp[99].ToString(); RM67120_B208.Text = arrtmp[101].ToString();
                RM67120_R224.Text = arrtmp[103].ToString(); RM67120_G224.Text = arrtmp[105].ToString(); RM67120_B224.Text = arrtmp[107].ToString();
                RM67120_R232.Text = arrtmp[109].ToString(); RM67120_G232.Text = arrtmp[111].ToString(); RM67120_B232.Text = arrtmp[113].ToString();
                RM67120_R240.Text = arrtmp[115].ToString(); RM67120_G240.Text = arrtmp[117].ToString(); RM67120_B240.Text = arrtmp[119].ToString();
                RM67120_R244.Text = arrtmp[121].ToString(); RM67120_G244.Text = arrtmp[123].ToString(); RM67120_B244.Text = arrtmp[125].ToString();
                RM67120_R248.Text = arrtmp[127].ToString(); RM67120_G248.Text = arrtmp[129].ToString(); RM67120_B248.Text = arrtmp[131].ToString();
                RM67120_R250.Text = arrtmp[133].ToString(); RM67120_G250.Text = arrtmp[135].ToString(); RM67120_B250.Text = arrtmp[137].ToString();
                RM67120_R252.Text = arrtmp[139].ToString(); RM67120_G252.Text = arrtmp[141].ToString(); RM67120_B252.Text = arrtmp[143].ToString();
                RM67120_R254.Text = arrtmp[145].ToString(); RM67120_G254.Text = arrtmp[147].ToString(); RM67120_B254.Text = arrtmp[149].ToString();
                RM67120_R255.Text = arrtmp[151].ToString(); RM67120_G255.Text = arrtmp[153].ToString(); RM67120_B255.Text = arrtmp[155].ToString();
            }
        }
        private void RM67120_GAMMA_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[58];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 58;
            Send_buf[0] = 0x08;
            Send_buf[2] = 0x35;//数据长度
            switch (btnTmp.Name)
            {
                case "RM67120_GammaR_Red":             //Read R
                    {
                        Setting.TempRecord.RM67120CmdType = 0x03;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = 0x00;
                    }
                    break;
                case "RM67120_GammaR_Green":
                    {
                        Setting.TempRecord.RM67120CmdType = 0x04;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = 0x42;
                    }
                    break;
                case "RM67120_GammaR_Blue":
                    {
                        Setting.TempRecord.RM67120CmdType = 0x05;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = 0x81;
                    }
                    break;
                //--------------------------------------
                case "RM67120_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x00;

                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(RM67120_R0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(RM67120_R0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(RM67120_R1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(RM67120_R1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(RM67120_R3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(RM67120_R3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(RM67120_R5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(RM67120_R5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(RM67120_R7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(RM67120_R7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(RM67120_R11.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(RM67120_R11.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(RM67120_R15.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(RM67120_R15.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(RM67120_R23.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(RM67120_R23.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(RM67120_R31.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(RM67120_R31.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(RM67120_R47.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(RM67120_R47.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(RM67120_R63.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(RM67120_R63.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(RM67120_R95.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(RM67120_R95.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(RM67120_R127.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(RM67120_R127.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(RM67120_R128.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(RM67120_R128.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(RM67120_R160.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(RM67120_R160.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(RM67120_R192.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(RM67120_R192.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(RM67120_R208.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(RM67120_R208.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(RM67120_R224.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(RM67120_R224.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(RM67120_R232.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(RM67120_R232.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(RM67120_R240.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(RM67120_R240.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(RM67120_R244.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(RM67120_R244.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(RM67120_R248.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(RM67120_R248.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(RM67120_R250.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(RM67120_R250.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(RM67120_R252.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(RM67120_R252.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(RM67120_R254.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(RM67120_R254.Value.ToString())) & 0xff);
                        Send_buf[54] = Convert.ToByte(Convert.ToUInt16(RM67120_R255.Value.ToString()) >> 8);
                        Send_buf[55] = Convert.ToByte((Convert.ToUInt16(RM67120_R255.Value.ToString())) & 0xff);

                    }
                    break;
                case "RM67120_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x42;

                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(RM67120_G0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(RM67120_G0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(RM67120_G1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(RM67120_G1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(RM67120_G3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(RM67120_G3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(RM67120_G5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(RM67120_G5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(RM67120_G7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(RM67120_G7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(RM67120_G11.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(RM67120_G11.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(RM67120_G15.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(RM67120_G15.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(RM67120_G23.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(RM67120_G23.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(RM67120_G31.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(RM67120_G31.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(RM67120_G47.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(RM67120_G47.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(RM67120_G63.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(RM67120_G63.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(RM67120_G95.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(RM67120_G95.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(RM67120_G127.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(RM67120_G127.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(RM67120_G128.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(RM67120_G128.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(RM67120_G160.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(RM67120_G160.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(RM67120_G192.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(RM67120_G192.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(RM67120_G208.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(RM67120_G208.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(RM67120_G224.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(RM67120_G224.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(RM67120_G232.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(RM67120_G232.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(RM67120_G240.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(RM67120_G240.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(RM67120_G244.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(RM67120_G244.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(RM67120_G248.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(RM67120_G248.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(RM67120_G250.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(RM67120_G250.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(RM67120_G252.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(RM67120_G252.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(RM67120_G254.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(RM67120_G254.Value.ToString())) & 0xff);
                        Send_buf[54] = Convert.ToByte(Convert.ToUInt16(RM67120_G255.Value.ToString()) >> 8);
                        Send_buf[55] = Convert.ToByte((Convert.ToUInt16(RM67120_G255.Value.ToString())) & 0xff);
                    }
                    break;
                case "RM67120_GammaW_Blue":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x81;

                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(RM67120_B0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(RM67120_B0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(RM67120_B1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(RM67120_B1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(RM67120_B3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(RM67120_B3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(RM67120_B5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(RM67120_B5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(RM67120_B7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(RM67120_B7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(RM67120_B11.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(RM67120_B11.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(RM67120_B15.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(RM67120_B15.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(RM67120_B23.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(RM67120_B23.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(RM67120_B31.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(RM67120_B31.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(RM67120_B47.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(RM67120_B47.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(RM67120_B63.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(RM67120_B63.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(RM67120_B95.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(RM67120_B95.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(RM67120_B127.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(RM67120_B127.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(RM67120_B128.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(RM67120_B128.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(RM67120_B160.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(RM67120_B160.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(RM67120_B192.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(RM67120_B192.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(RM67120_B208.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(RM67120_B208.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(RM67120_B224.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(RM67120_B224.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(RM67120_B232.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(RM67120_B232.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(RM67120_B240.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(RM67120_B240.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(RM67120_B244.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(RM67120_B244.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(RM67120_B248.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(RM67120_B248.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(RM67120_B250.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(RM67120_B250.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(RM67120_B252.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(RM67120_B252.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(RM67120_B254.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(RM67120_B254.Value.ToString())) & 0xff);
                        Send_buf[54] = Convert.ToByte(Convert.ToUInt16(RM67120_B255.Value.ToString()) >> 8);
                        Send_buf[55] = Convert.ToByte((Convert.ToUInt16(RM67120_B255.Value.ToString())) & 0xff);
                    }
                    break;
                default:
                    break;
            }

            CRCData.CalculateCrc16(Send_buf, out Send_buf[56], out Send_buf[57]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 58);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        private void RM67120_GAMMA_Change(object sender, EventArgs e)
        {
            double tmp;
            if (RM67120_GAMMA_LINK_R.Checked == false)
            {
                //----------------------------------------------------R--------------------------------------------------
                tmp = Convert.ToDouble(RM67120_R127.Value.ToString()) * 0.96969697 + Convert.ToDouble(RM67120_R160.Value.ToString()) * 0.03030303;
                RM67120_R128.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.65957447 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.34042553;
                RM67120_R224.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.48936170 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.51063830;
                RM67120_R232.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.31914894 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.68085106;
                RM67120_R240.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.23404255 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.76595745;
                RM67120_R244.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.14893617 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.85106383;
                RM67120_R248.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.10638298 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.89361702;
                RM67120_R250.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.06382979 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.93617021;
                RM67120_R252.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_R208.Value.ToString()) * 0.02127660 + Convert.ToDouble(RM67120_R255.Value.ToString()) * 0.97872340;
                RM67120_R254.Value = Convert.ToUInt16(tmp);
            }
            if (RM67120_GAMMA_LINK_G.Checked == false)
            {
                //----------------------------------------------------G--------------------------------------------------
                tmp = Convert.ToDouble(RM67120_G127.Value.ToString()) * 0.96969697 + Convert.ToDouble(RM67120_G160.Value.ToString()) * 0.03030303;
                RM67120_G128.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.65957447 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.34042553;
                RM67120_G224.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.48936170 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.51063830;
                RM67120_G232.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.31914894 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.68085106;
                RM67120_G240.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.23404255 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.76595745;
                RM67120_G244.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.14893617 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.85106383;
                RM67120_G248.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.10638298 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.89361702;
                RM67120_G250.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.06382979 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.93617021;
                RM67120_G252.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_G208.Value.ToString()) * 0.02127660 + Convert.ToDouble(RM67120_G255.Value.ToString()) * 0.97872340;
                RM67120_G254.Value = Convert.ToUInt16(tmp);
            }
            if (RM67120_GAMMA_LINK_B.Checked == false)
            {
                //----------------------------------------------------B--------------------------------------------------
                tmp = Convert.ToDouble(RM67120_B127.Value.ToString()) * 0.96969697 + Convert.ToDouble(RM67120_B160.Value.ToString()) * 0.03030303;
                RM67120_B128.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.65957447 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.34042553;
                RM67120_B224.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.48936170 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.51063830;
                RM67120_B232.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.31914894 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.68085106;
                RM67120_B240.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.23404255 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.76595745;
                RM67120_B244.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.14893617 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.85106383;
                RM67120_B248.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.10638298 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.89361702;
                RM67120_B250.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.06382979 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.93617021;
                RM67120_B252.Value = Convert.ToUInt16(tmp);
                tmp = Convert.ToDouble(RM67120_B208.Value.ToString()) * 0.02127660 + Convert.ToDouble(RM67120_B255.Value.ToString()) * 0.97872340;
                RM67120_B254.Value = Convert.ToUInt16(tmp);
            }
        }
        private void RM67120_RegWR_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Int32 DataNum;
            string strLine = Convert.ToString(txtRegData.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组

            switch (btnTmp.Name)
            {
                case "RM67120_RegW":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x08;
                        Send_buf[1] = 0x01;
                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);


                        try
                        {
                            frmHelp.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;

                case "RM67120_RegR":
                    {
                        Setting.TempRecord.RM67120CmdType = 0x02;
                        try
                        {
                            DataNum = Convert.ToInt32(txtDataNum.Text) + 1;
                            Setting.TempRecord.cmdLen = DataNum + 5;
                            Send_buf = new byte[DataNum + 5];
                            Send_buf[0] = 0x08;
                            Send_buf[1] = 0x02;
                            Send_buf[2] = byte.Parse(Convert.ToString(DataNum));
                            Send_buf[3] = byte.Parse((Convert.ToInt32(arr[0], 16)).ToString());
                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + DataNum - 2], out Send_buf[5 + DataNum - 1]);
                        }
                        catch
                        {
                            MessageBox.Show("读取长度有误，请检查", "错误");
                            break;
                        }
                        try
                        {
                            frmHelp.comPort.Write(Send_buf, 0, 5 + DataNum);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;

                default: break;
            }

            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        private void RM67120_Others_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;

            Send_buf[0] = 0x08;
            Send_buf[2] = 0x02;
            switch (btnTmp.Name)
            {
                case "RM67120_OTP":         //otp
                    {
                        Send_buf[1] = 0x0A;
                        {       //保存待otp的gamma
                            FileStream fs = new FileStream("../OTP_gamma_120.txt", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Close();
                            StreamWriter sw = new StreamWriter(fs.Name, false, Encoding.UTF8);
                            string str = null;
                            str = str + RM67120_R0.Text + "," + RM67120_G0.Text + "," + RM67120_B0.Text + "\r\n";
                            str = str + RM67120_R1.Text + "," + RM67120_G1.Text + "," + RM67120_B1.Text + "\r\n";
                            str = str + RM67120_R3.Text + "," + RM67120_G3.Text + "," + RM67120_B3.Text + "\r\n";
                            str = str + RM67120_R5.Text + "," + RM67120_G5.Text + "," + RM67120_B5.Text + "\r\n";
                            str = str + RM67120_R7.Text + "," + RM67120_G7.Text + "," + RM67120_B7.Text + "\r\n";
                            str = str + RM67120_R11.Text + "," + RM67120_G11.Text + "," + RM67120_B11.Text + "\r\n";
                            str = str + RM67120_R15.Text + "," + RM67120_G15.Text + "," + RM67120_B15.Text + "\r\n";
                            str = str + RM67120_R23.Text + "," + RM67120_G23.Text + "," + RM67120_B23.Text + "\r\n";
                            str = str + RM67120_R31.Text + "," + RM67120_G31.Text + "," + RM67120_B31.Text + "\r\n";
                            str = str + RM67120_R47.Text + "," + RM67120_G47.Text + "," + RM67120_B47.Text + "\r\n";
                            str = str + RM67120_R63.Text + "," + RM67120_G63.Text + "," + RM67120_B63.Text + "\r\n";
                            str = str + RM67120_R95.Text + "," + RM67120_G95.Text + "," + RM67120_B95.Text + "\r\n";
                            str = str + RM67120_R127.Text + "," + RM67120_G127.Text + "," + RM67120_B127.Text + "\r\n";
                            str = str + RM67120_R128.Text + "," + RM67120_G128.Text + "," + RM67120_B128.Text + "\r\n";
                            str = str + RM67120_R160.Text + "," + RM67120_G160.Text + "," + RM67120_B160.Text + "\r\n";
                            str = str + RM67120_R192.Text + "," + RM67120_G192.Text + "," + RM67120_B192.Text + "\r\n";
                            str = str + RM67120_R208.Text + "," + RM67120_G208.Text + "," + RM67120_B208.Text + "\r\n";
                            str = str + RM67120_R224.Text + "," + RM67120_G224.Text + "," + RM67120_B224.Text + "\r\n";
                            str = str + RM67120_R232.Text + "," + RM67120_G232.Text + "," + RM67120_B232.Text + "\r\n";
                            str = str + RM67120_R240.Text + "," + RM67120_G240.Text + "," + RM67120_B240.Text + "\r\n";
                            str = str + RM67120_R244.Text + "," + RM67120_G244.Text + "," + RM67120_B244.Text + "\r\n";
                            str = str + RM67120_R248.Text + "," + RM67120_G248.Text + "," + RM67120_B248.Text + "\r\n";
                            str = str + RM67120_R250.Text + "," + RM67120_G250.Text + "," + RM67120_B250.Text + "\r\n";
                            str = str + RM67120_R252.Text + "," + RM67120_G252.Text + "," + RM67120_B252.Text + "\r\n";
                            str = str + RM67120_R254.Text + "," + RM67120_G254.Text + "," + RM67120_B254.Text + "\r\n";
                            str = str + RM67120_R255.Text + "," + RM67120_G255.Text + "," + RM67120_B255.Text + "\r\n";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                        }
                    }
                    break;
                case "RM67120_OTP_ID":         //Read
                    {
                        Setting.TempRecord.RM67120CmdType = 0x01;   //读普通寄存器
                        Send_buf[1] = 0x0C;
                    }
                    break;

                case "RM67120_OTP_time_Read":         //Read
                    {
                        Setting.TempRecord.RM67120CmdType = 0x01;   //读普通寄存器
                        Send_buf[1] = 0x0B;
                    }
                    break;

                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }

        //RM67120
        /*
        private void btnOTPchk120_Click(object sender, EventArgs e)
        {
            bool flag = true;
            int i = 0;
            FileStream fs = new FileStream("../OTP_gamma_120.txt", FileMode.Open, FileAccess.Read);//读取gamma信息
            StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
            streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
            string strLine = streamReader.ReadLine();
            string strtmp = null;
            while (!string.IsNullOrEmpty(strLine))
            {
                strtmp = strtmp + strLine + ",";
                strLine = streamReader.ReadLine(); //循环读取下一行
            }
            fs.Close(); //关闭流
            streamReader.Close();
            string[] arrtmp_otp = strtmp.Split(new Char[] { ',' });
            string[] arrtmp_check = new string[78];

            frmHelp.LCD_Cfg_Click(frmHelp.btnLCDcfg, e);
            SSD28xx_Download_only_Click(SSD28xx_Download_only, e);
            RM67120_GAMMA_Click(RM67120_GammaR_Red, e);
            Application.DoEvents();
            Thread.Sleep(2 * 1000);
            Application.DoEvents();
            RM67120_GAMMA_Click(RM67120_GammaR_Green, e);
            Application.DoEvents();
            Thread.Sleep(2 * 1000);
            Application.DoEvents();
            RM67120_GAMMA_Click(RM67120_GammaR_Blue, e);
            Application.DoEvents();
            Thread.Sleep(2 * 1000);
            Application.DoEvents();

            arrtmp_check[0] = RM67120_R0.Text; arrtmp_check[1] = RM67120_G0.Text; arrtmp_check[2] = RM67120_B0.Text;
            arrtmp_check[3] = RM67120_R1.Text; arrtmp_check[4] = RM67120_G1.Text; arrtmp_check[5] = RM67120_B1.Text;
            arrtmp_check[6] = RM67120_R3.Text; arrtmp_check[7] = RM67120_G3.Text; arrtmp_check[8] = RM67120_B3.Text;
            arrtmp_check[9] = RM67120_R5.Text; arrtmp_check[10] = RM67120_G5.Text; arrtmp_check[11] = RM67120_B5.Text;
            arrtmp_check[12] = RM67120_R7.Text; arrtmp_check[13] = RM67120_G7.Text; arrtmp_check[14] = RM67120_B7.Text;
            arrtmp_check[15] = RM67120_R11.Text; arrtmp_check[16] = RM67120_G11.Text; arrtmp_check[17] = RM67120_B11.Text;
            arrtmp_check[18] = RM67120_R15.Text; arrtmp_check[19] = RM67120_G15.Text; arrtmp_check[20] = RM67120_B15.Text;
            arrtmp_check[21] = RM67120_R23.Text; arrtmp_check[22] = RM67120_G23.Text; arrtmp_check[23] = RM67120_B23.Text;
            arrtmp_check[24] = RM67120_R31.Text; arrtmp_check[25] = RM67120_G31.Text; arrtmp_check[26] = RM67120_B31.Text;
            arrtmp_check[27] = RM67120_R47.Text; arrtmp_check[28] = RM67120_G47.Text; arrtmp_check[29] = RM67120_B47.Text;
            arrtmp_check[30] = RM67120_R63.Text; arrtmp_check[31] = RM67120_G63.Text; arrtmp_check[32] = RM67120_B63.Text;
            arrtmp_check[33] = RM67120_R95.Text; arrtmp_check[34] = RM67120_G95.Text; arrtmp_check[35] = RM67120_B95.Text;
            arrtmp_check[36] = RM67120_R127.Text; arrtmp_check[37] = RM67120_G127.Text; arrtmp_check[38] = RM67120_B127.Text;
            arrtmp_check[39] = RM67120_R128.Text; arrtmp_check[40] = RM67120_G128.Text; arrtmp_check[41] = RM67120_B128.Text;
            arrtmp_check[42] = RM67120_R160.Text; arrtmp_check[43] = RM67120_G160.Text; arrtmp_check[44] = RM67120_B160.Text;
            arrtmp_check[45] = RM67120_R192.Text; arrtmp_check[46] = RM67120_G192.Text; arrtmp_check[47] = RM67120_B192.Text;
            arrtmp_check[48] = RM67120_R208.Text; arrtmp_check[49] = RM67120_G208.Text; arrtmp_check[50] = RM67120_B208.Text;
            arrtmp_check[51] = RM67120_R224.Text; arrtmp_check[52] = RM67120_G224.Text; arrtmp_check[53] = RM67120_B224.Text;
            arrtmp_check[54] = RM67120_R232.Text; arrtmp_check[55] = RM67120_G232.Text; arrtmp_check[56] = RM67120_B232.Text;
            arrtmp_check[57] = RM67120_R240.Text; arrtmp_check[58] = RM67120_G240.Text; arrtmp_check[59] = RM67120_B240.Text;
            arrtmp_check[60] = RM67120_R244.Text; arrtmp_check[61] = RM67120_G244.Text; arrtmp_check[62] = RM67120_B244.Text;
            arrtmp_check[63] = RM67120_R248.Text; arrtmp_check[64] = RM67120_G248.Text; arrtmp_check[65] = RM67120_B248.Text;
            arrtmp_check[66] = RM67120_R250.Text; arrtmp_check[67] = RM67120_G250.Text; arrtmp_check[68] = RM67120_B250.Text;
            arrtmp_check[69] = RM67120_R252.Text; arrtmp_check[70] = RM67120_G252.Text; arrtmp_check[71] = RM67120_B252.Text;
            arrtmp_check[72] = RM67120_R254.Text; arrtmp_check[73] = RM67120_G254.Text; arrtmp_check[74] = RM67120_B254.Text;
            arrtmp_check[75] = RM67120_R255.Text; arrtmp_check[76] = RM67120_G255.Text; arrtmp_check[77] = RM67120_B255.Text;

            while (flag)
            {
                if (i == 78)
                {
                    MessageBox.Show("RM67120 OTP Check succeed！", "otp check");
                    flag = false;
                }
                else if (string.Compare(arrtmp_check[i], arrtmp_otp[i]) != 0) //=0:equal
                {
                    flag = false;
                    MessageBox.Show("RM67120 OTP Check failed！", "otp check");
                }
                else i++;
            }
        }
        */
        private void btn120Stop_Click(object sender, EventArgs e)
        {
            T20.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }
        private void btnCalculate1_Click(object sender, EventArgs e)
        {
            text120_255.Text = (Math.Pow((Parttern_RM67120[0] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_254.Text = (Math.Pow((Parttern_RM67120[1] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_252.Text = (Math.Pow((Parttern_RM67120[2] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_250.Text = (Math.Pow((Parttern_RM67120[3] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_248.Text = (Math.Pow((Parttern_RM67120[4] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_244.Text = (Math.Pow((Parttern_RM67120[5] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_240.Text = (Math.Pow((Parttern_RM67120[6] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_232.Text = (Math.Pow((Parttern_RM67120[7] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_224.Text = (Math.Pow((Parttern_RM67120[8] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_208.Text = (Math.Pow((Parttern_RM67120[9] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_192.Text = (Math.Pow((Parttern_RM67120[10] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_160.Text = (Math.Pow((Parttern_RM67120[11] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_128.Text = (Math.Pow((Parttern_RM67120[12] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_127.Text = (Math.Pow((Parttern_RM67120[13] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_95.Text = (Math.Pow((Parttern_RM67120[14] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_63.Text = (Math.Pow((Parttern_RM67120[15] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_47.Text = (Math.Pow((Parttern_RM67120[16] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_31.Text = (Math.Pow((Parttern_RM67120[17] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_23.Text = (Math.Pow((Parttern_RM67120[18] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_15.Text = (Math.Pow((Parttern_RM67120[19] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_11.Text = (Math.Pow((Parttern_RM67120[20] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_7.Text = (Math.Pow((Parttern_RM67120[21] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_5.Text = (Math.Pow((Parttern_RM67120[22] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_3.Text = (Math.Pow((Parttern_RM67120[23] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
            text120_1.Text = (Math.Pow((Parttern_RM67120[24] / 255.0), Convert.ToDouble(textgamma1.Text)) * Convert.ToDouble(textlum1.Text)).ToString("F4");
        }

        private void T20_Tick(object sender, EventArgs e)
        {
            RM67120_auto_Gamma(null, null);
        }

        private void btnAutogamma1_Click(object sender, EventArgs e)
        {
            int flag = 1;
            double Lr_d, Lg_d, Lb_d;
            D_lums = new double[25, 3];
            D_lum = new double[25];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            D_lum[0] = Convert.ToDouble(text120_255.Text);
            D_lum[1] = Convert.ToDouble(text120_254.Text);
            D_lum[2] = Convert.ToDouble(text120_252.Text);
            D_lum[3] = Convert.ToDouble(text120_250.Text);
            D_lum[4] = Convert.ToDouble(text120_248.Text);
            D_lum[5] = Convert.ToDouble(text120_244.Text);
            D_lum[6] = Convert.ToDouble(text120_240.Text);
            D_lum[7] = Convert.ToDouble(text120_232.Text);
            D_lum[8] = Convert.ToDouble(text120_224.Text);
            D_lum[9] = Convert.ToDouble(text120_208.Text);
            D_lum[10] = Convert.ToDouble(text120_192.Text);
            D_lum[11] = Convert.ToDouble(text120_160.Text);
            D_lum[12] = Convert.ToDouble(text120_128.Text);
            D_lum[13] = Convert.ToDouble(text120_127.Text);
            D_lum[14] = Convert.ToDouble(text120_95.Text);
            D_lum[15] = Convert.ToDouble(text120_63.Text);
            D_lum[16] = Convert.ToDouble(text120_47.Text);
            D_lum[17] = Convert.ToDouble(text120_31.Text);
            D_lum[18] = Convert.ToDouble(text120_23.Text);
            D_lum[19] = Convert.ToDouble(text120_15.Text);
            D_lum[20] = Convert.ToDouble(text120_11.Text);
            D_lum[21] = Convert.ToDouble(text120_7.Text);
            D_lum[22] = Convert.ToDouble(text120_5.Text);
            D_lum[23] = Convert.ToDouble(text120_3.Text);
            D_lum[24] = Convert.ToDouble(text120_1.Text);

            D_x = Convert.ToDouble(textx1.Text);
            D_y = Convert.ToDouble(texty1.Text);
            Lr_d = CaSDKObj.R_y * ((D_y - CaSDKObj.G_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.G_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.G_y) * (D_x - CaSDKObj.R_x) + (D_x - CaSDKObj.G_x) * (CaSDKObj.R_y - D_y));
            Lg_d = CaSDKObj.G_y * ((D_y - CaSDKObj.R_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.R_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.R_y) * (D_x - CaSDKObj.G_x) + (D_x - CaSDKObj.R_x) * (CaSDKObj.G_y - D_y));
            Lb_d = 1.0;

            for (int i = 0; i < 25; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
            }


            switch (flag)
            {
                case 1://寄存器值与亮度正比
                    {
                        lum_off = Convert.ToDouble(textlum1_off.Text);
                        x_off = Convert.ToDouble(textx1_off.Text);
                        y_off = Convert.ToDouble(texty1_off.Text);
                        Application.DoEvents();
                        frmHelp.OLED_Show_Click(frmHelp.btnwhite, e);
                        T20.Enabled = true;
                    }
                    break;
                case 2://寄存器值与亮度反比
                    break;
                default:
                    break;
            }
        }
        private void RM67120_auto_Gamma(Object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if ((frmHelp.CASDK_LUM < (D_lum[index] + lum_off)) && (frmHelp.CASDK_LUM > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((frmHelp.CASDK_y < (D_y + y_off)) && (frmHelp.CASDK_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((frmHelp.CASDK_x < (D_x + x_off)) && (frmHelp.CASDK_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index <= 24)
                {
                    if ((adjust_class == "btnAutogamma1") && (adjust_num == 1))
                    {
                        switch (index)
                        {
                            case 1:
                                {
                                    RM67120_R254.Value = RM67120_R255.Value - 3;
                                    RM67120_G254.Value = RM67120_G255.Value - 3;
                                    RM67120_B254.Value = RM67120_B255.Value - 3;
                                    lum_off = Convert.ToDouble(text120_254_off.Text);
                                }
                                break;
                            case 2:
                                {
                                    RM67120_R252.Value = RM67120_R254.Value - 3;
                                    RM67120_G252.Value = RM67120_G254.Value - 3;
                                    RM67120_B252.Value = RM67120_B254.Value - 3;
                                    lum_off = Convert.ToDouble(text120_252_off.Text);
                                }
                                break;
                            case 3:
                                {
                                    RM67120_R250.Value = RM67120_R252.Value - 3;
                                    RM67120_G250.Value = RM67120_G252.Value - 3;
                                    RM67120_B250.Value = RM67120_B252.Value - 3;
                                    lum_off = Convert.ToDouble(text120_250_off.Text);
                                }
                                break;
                            case 4:
                                {
                                    RM67120_R248.Value = RM67120_R250.Value - 3;
                                    RM67120_G248.Value = RM67120_G250.Value - 3;
                                    RM67120_B248.Value = RM67120_B250.Value - 3;
                                    lum_off = Convert.ToDouble(text120_248_off.Text);
                                }
                                break;
                            case 5:
                                {
                                    RM67120_R244.Value = RM67120_R248.Value - 3;
                                    RM67120_G244.Value = RM67120_G248.Value - 3;
                                    RM67120_B244.Value = RM67120_B248.Value - 3;
                                    lum_off = Convert.ToDouble(text120_244_off.Text);
                                }
                                break;
                            case 6:
                                {
                                    RM67120_R240.Value = RM67120_R244.Value - 3;
                                    RM67120_G240.Value = RM67120_G244.Value - 3;
                                    RM67120_B240.Value = RM67120_B244.Value - 3;
                                    lum_off = Convert.ToDouble(text120_240_off.Text);
                                }
                                break;
                            case 7:
                                {
                                    RM67120_R232.Value = RM67120_R240.Value - 3;
                                    RM67120_G232.Value = RM67120_G240.Value - 3;
                                    RM67120_B232.Value = RM67120_B240.Value - 3;
                                    lum_off = Convert.ToDouble(text120_232_off.Text);
                                }
                                break;
                            case 8:
                                {
                                    RM67120_R224.Value = RM67120_R232.Value - 3;
                                    RM67120_G224.Value = RM67120_G232.Value - 3;
                                    RM67120_B224.Value = RM67120_B232.Value - 3;
                                    lum_off = Convert.ToDouble(text120_224_off.Text);
                                }
                                break;
                            case 9:
                                {
                                    RM67120_R208.Value = RM67120_R224.Value - 32;
                                    RM67120_G208.Value = RM67120_G224.Value - 32;
                                    RM67120_B208.Value = RM67120_B224.Value - 32;
                                    lum_off = Convert.ToDouble(text120_208_off.Text);
                                }
                                break;
                            case 10:
                                {
                                    RM67120_R192.Value = RM67120_R208.Value - 32;
                                    RM67120_G192.Value = RM67120_G208.Value - 32;
                                    RM67120_B192.Value = RM67120_B208.Value - 32;
                                    lum_off = Convert.ToDouble(text120_192_off.Text);
                                }
                                break;
                            case 11:
                                {
                                    RM67120_R160.Value = RM67120_R192.Value - 32;
                                    RM67120_G160.Value = RM67120_G192.Value - 32;
                                    RM67120_B160.Value = RM67120_B192.Value - 32;
                                    lum_off = Convert.ToDouble(text120_160_off.Text);
                                }
                                break;
                            case 12:
                                {
                                    RM67120_R128.Value = RM67120_R160.Value - 32;
                                    RM67120_G128.Value = RM67120_G160.Value - 32;
                                    RM67120_B128.Value = RM67120_B160.Value - 32;
                                    lum_off = Convert.ToDouble(text120_128_off.Text) * Convert.ToDouble(text120_128.Text) / 100;
                                }
                                break;
                            case 13:
                                {
                                    RM67120_R127.Value = RM67120_R128.Value - 3;
                                    RM67120_G127.Value = RM67120_G128.Value - 3;
                                    RM67120_B127.Value = RM67120_B128.Value - 3;
                                    lum_off = Convert.ToDouble(text120_127_off.Text) * Convert.ToDouble(text120_127.Text) / 100;
                                }
                                break;
                            case 14:
                                {
                                    RM67120_R95.Value = RM67120_R127.Value - 32;
                                    RM67120_G95.Value = RM67120_G127.Value - 32;
                                    RM67120_B95.Value = RM67120_B127.Value - 32;
                                    lum_off = Convert.ToDouble(text120_95_off.Text) * Convert.ToDouble(text120_95.Text) / 100;
                                }
                                break;
                            case 15:
                                {
                                    RM67120_R63.Value = RM67120_R95.Value - 32;
                                    RM67120_G63.Value = RM67120_G95.Value - 32;
                                    RM67120_B63.Value = RM67120_B95.Value - 32;
                                    lum_off = Convert.ToDouble(text120_63_off.Text) * Convert.ToDouble(text120_63.Text) / 100;
                                }
                                break;
                            case 16:
                                {
                                    RM67120_R47.Value = RM67120_R63.Value - 32;
                                    RM67120_G47.Value = RM67120_G63.Value - 32;
                                    RM67120_B47.Value = RM67120_B63.Value - 32;
                                    lum_off = Convert.ToDouble(text120_47_off.Text) * Convert.ToDouble(text120_47.Text) / 100;
                                }
                                break;
                            case 17:
                                {
                                    RM67120_R31.Value = RM67120_R47.Value - 32;
                                    RM67120_G31.Value = RM67120_G47.Value - 32;
                                    RM67120_B31.Value = RM67120_B47.Value - 32;
                                    lum_off = Convert.ToDouble(text120_31_off.Text) * Convert.ToDouble(text120_31.Text) / 100;
                                }
                                break;
                            case 18:
                                {
                                    RM67120_R23.Value = RM67120_R31.Value - 32;
                                    RM67120_G23.Value = RM67120_G31.Value - 32;
                                    RM67120_B23.Value = RM67120_B31.Value - 32;
                                    lum_off = Convert.ToDouble(text120_23_off.Text) * Convert.ToDouble(text120_23.Text) / 100;
                                }
                                break;
                            case 19:
                                {
                                    RM67120_R15.Value = RM67120_R23.Value - 32;
                                    RM67120_G15.Value = RM67120_G23.Value - 32;
                                    RM67120_B15.Value = RM67120_B23.Value - 32;
                                    lum_off = Convert.ToDouble(text120_15_off.Text) * Convert.ToDouble(text120_15.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 20:
                                {
                                    RM67120_R11.Value = RM67120_R15.Value - 32;
                                    RM67120_G11.Value = RM67120_G15.Value - 32;
                                    RM67120_B11.Value = RM67120_B15.Value - 32;
                                    lum_off = Convert.ToDouble(text120_11_off.Text) * Convert.ToDouble(text120_11.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 21:
                                {
                                    RM67120_R7.Value = RM67120_R11.Value - 32;
                                    RM67120_G7.Value = RM67120_G11.Value - 32;
                                    RM67120_B7.Value = RM67120_B11.Value - 32;
                                    lum_off = Convert.ToDouble(text120_7_off.Text) * Convert.ToDouble(text120_7.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 22:
                                {
                                    RM67120_R5.Value = RM67120_R7.Value - 32;
                                    RM67120_G5.Value = RM67120_G7.Value - 32;
                                    RM67120_B5.Value = RM67120_B7.Value - 32;
                                    lum_off = Convert.ToDouble(text120_5_off.Text) * Convert.ToDouble(text120_5.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 23:
                                {
                                    RM67120_R3.Value = RM67120_R5.Value - 32;
                                    RM67120_G3.Value = RM67120_G5.Value - 32;
                                    RM67120_B3.Value = RM67120_B5.Value - 32;
                                    lum_off = Convert.ToDouble(text120_3_off.Text) * Convert.ToDouble(text120_3.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 24:
                                {
                                    RM67120_R1.Value = RM67120_R3.Value - 32;
                                    RM67120_G1.Value = RM67120_G3.Value - 32;
                                    RM67120_B1.Value = RM67120_B3.Value - 32;
                                    lum_off = Convert.ToDouble(text120_1_off.Text) * Convert.ToDouble(text120_1.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                        }
                        RM67120_GAMMA_Click(RM67120_GammaW_Red, e);//调用寄存器写函数，把255阶R-gamma写入寄存器中。
                        RM67120_GAMMA_Click(RM67120_GammaW_Green, e);//调用寄存器写函数，把255阶G-gamma写入寄存器中。
                        RM67120_GAMMA_Click(RM67120_GammaW_Blue, e);//调用寄存器写函数，把255阶B-gamma写入寄存器中。
                    }
                    else
                    {
                        switch (index)
                        {
                            case 1:
                                lum_off = Convert.ToDouble(text120_254_off.Text);
                                break;
                            case 2:
                                lum_off = Convert.ToDouble(text120_252_off.Text);
                                break;
                            case 3:
                                lum_off = Convert.ToDouble(text120_250_off.Text);
                                break;
                            case 4:
                                lum_off = Convert.ToDouble(text120_248_off.Text);
                                break;
                            case 5:
                                lum_off = Convert.ToDouble(text120_244_off.Text);
                                break;
                            case 6:
                                lum_off = Convert.ToDouble(text120_240_off.Text);
                                break;
                            case 7:
                                lum_off = Convert.ToDouble(text120_232_off.Text);
                                break;
                            case 8:
                                lum_off = Convert.ToDouble(text120_224_off.Text);
                                break;
                            case 9:
                                lum_off = Convert.ToDouble(text120_208_off.Text);
                                break;
                            case 10:
                                lum_off = Convert.ToDouble(text120_192_off.Text);
                                break;
                            case 11:
                                lum_off = Convert.ToDouble(text120_160_off.Text);
                                break;
                            case 12:
                                lum_off = Convert.ToDouble(text120_128_off.Text) * Convert.ToDouble(text120_128.Text) / 100;
                                break;
                            case 13:
                                lum_off = Convert.ToDouble(text120_127_off.Text) * Convert.ToDouble(text120_127.Text) / 100;
                                break;
                            case 14:
                                lum_off = Convert.ToDouble(text120_95_off.Text) * Convert.ToDouble(text120_95.Text) / 100;
                                break;
                            case 15:
                                lum_off = Convert.ToDouble(text120_63_off.Text) * Convert.ToDouble(text120_63.Text) / 100;
                                break;
                            case 16:
                                lum_off = Convert.ToDouble(text120_47_off.Text) * Convert.ToDouble(text120_47.Text) / 100;
                                break;
                            case 17:
                                lum_off = Convert.ToDouble(text120_31_off.Text) * Convert.ToDouble(text120_31.Text) / 100;
                                break;
                            case 18:
                                lum_off = Convert.ToDouble(text120_23_off.Text) * Convert.ToDouble(text120_23.Text) / 100;
                                break;
                            case 19:
                                {
                                    lum_off = Convert.ToDouble(text120_15_off.Text) * Convert.ToDouble(text120_15.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 20:
                                {
                                    lum_off = Convert.ToDouble(text120_11_off.Text) * Convert.ToDouble(text120_11.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 21:
                                {
                                    lum_off = Convert.ToDouble(text120_7_off.Text) * Convert.ToDouble(text120_7.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 22:
                                {
                                    lum_off = Convert.ToDouble(text120_5_off.Text) * Convert.ToDouble(text120_5.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 23:
                                {
                                    lum_off = Convert.ToDouble(text120_3_off.Text) * Convert.ToDouble(text120_3.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 24:
                                {
                                    lum_off = Convert.ToDouble(text120_1_off.Text) * Convert.ToDouble(text120_1.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                        }
                    }
                    frmHelp.numPatternR.Value = Parttern_RM67120[index];
                    frmHelp.numPatternG.Value = Parttern_RM67120[index];
                    frmHelp.numPatternB.Value = Parttern_RM67120[index];
                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, e);//写入Pattern参数
                    Thread.Sleep(10);
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                Lr_t = CaSDKObj.R_y * ((frmHelp.CASDK_y - CaSDKObj.G_y) * (CaSDKObj.B_x - frmHelp.CASDK_x) + (frmHelp.CASDK_x - CaSDKObj.G_x) * (frmHelp.CASDK_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((frmHelp.CASDK_y - CaSDKObj.G_y) * (frmHelp.CASDK_x - CaSDKObj.R_x) + (frmHelp.CASDK_x - CaSDKObj.G_x) * (CaSDKObj.R_y - frmHelp.CASDK_y));
                Lb_t = 1.0;
                Lg_t = CaSDKObj.G_y * ((frmHelp.CASDK_y - CaSDKObj.R_y) * (CaSDKObj.B_x - frmHelp.CASDK_x) + (frmHelp.CASDK_x - CaSDKObj.R_x) * (frmHelp.CASDK_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((frmHelp.CASDK_y - CaSDKObj.R_y) * (frmHelp.CASDK_x - CaSDKObj.G_x) + (frmHelp.CASDK_x - CaSDKObj.R_x) * (CaSDKObj.G_y - frmHelp.CASDK_y));
                lumr = frmHelp.CASDK_LUM * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = frmHelp.CASDK_LUM * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = frmHelp.CASDK_LUM * Lb_t / (Lr_t + Lg_t + Lb_t);

                switch (index)
                {
                    case 0:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R255.Value = RM67120_R255.Value - step_h;
                                    else RM67120_R255.Value = RM67120_R255.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R255.Value = RM67120_R255.Value - step_l;
                                    else RM67120_R255.Value = RM67120_R255.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G255.Value = RM67120_G255.Value - step_h;
                                    else RM67120_G255.Value = RM67120_G255.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G255.Value = RM67120_G255.Value - step_l;
                                    else RM67120_G255.Value = RM67120_G255.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B255.Value = RM67120_B255.Value - step_h;
                                    else RM67120_B255.Value = RM67120_B255.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B255.Value = RM67120_B255.Value - step_l;
                                    else RM67120_B255.Value = RM67120_B255.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 1:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R254.Value = RM67120_R254.Value - step_h;
                                    else RM67120_R254.Value = RM67120_R254.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R254.Value = RM67120_R254.Value - step_l;
                                    else RM67120_R254.Value = RM67120_R254.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G254.Value = RM67120_G254.Value - step_h;
                                    else RM67120_G254.Value = RM67120_G254.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G254.Value = RM67120_G254.Value - step_l;
                                    else RM67120_G254.Value = RM67120_G254.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B254.Value = RM67120_B254.Value - step_h;
                                    else RM67120_B254.Value = RM67120_B254.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B254.Value = RM67120_B254.Value - step_l;
                                    else RM67120_B254.Value = RM67120_B254.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 2:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R252.Value = RM67120_R252.Value - step_h;
                                    else RM67120_R252.Value = RM67120_R252.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R252.Value = RM67120_R252.Value - step_l;
                                    else RM67120_R252.Value = RM67120_R252.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G252.Value = RM67120_G252.Value - step_h;
                                    else RM67120_G252.Value = RM67120_G252.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G252.Value = RM67120_G252.Value - step_l;
                                    else RM67120_G252.Value = RM67120_G252.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B252.Value = RM67120_B252.Value - step_h;
                                    else RM67120_B252.Value = RM67120_B252.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B252.Value = RM67120_B252.Value - step_l;
                                    else RM67120_B252.Value = RM67120_B252.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 3:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R250.Value = RM67120_R250.Value - step_h;
                                    else RM67120_R250.Value = RM67120_R250.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R250.Value = RM67120_R250.Value - step_l;
                                    else RM67120_R250.Value = RM67120_R250.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G250.Value = RM67120_G250.Value - step_h;
                                    else RM67120_G250.Value = RM67120_G250.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G250.Value = RM67120_G250.Value - step_l;
                                    else RM67120_G250.Value = RM67120_G250.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B250.Value = RM67120_B250.Value - step_h;
                                    else RM67120_B250.Value = RM67120_B250.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B250.Value = RM67120_B250.Value - step_l;
                                    else RM67120_B250.Value = RM67120_B250.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 4:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R248.Value = RM67120_R248.Value - step_h;
                                    else RM67120_R248.Value = RM67120_R248.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R248.Value = RM67120_R248.Value - step_l;
                                    else RM67120_R248.Value = RM67120_R248.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G248.Value = RM67120_G248.Value - step_h;
                                    else RM67120_G248.Value = RM67120_G248.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G248.Value = RM67120_G248.Value - step_l;
                                    else RM67120_G248.Value = RM67120_G248.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B248.Value = RM67120_B248.Value - step_h;
                                    else RM67120_B248.Value = RM67120_B248.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B248.Value = RM67120_B248.Value - step_l;
                                    else RM67120_B248.Value = RM67120_B248.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 5:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R244.Value = RM67120_R244.Value - step_h;
                                    else RM67120_R244.Value = RM67120_R244.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R244.Value = RM67120_R244.Value - step_l;
                                    else RM67120_R244.Value = RM67120_R244.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G244.Value = RM67120_G244.Value - step_h;
                                    else RM67120_G244.Value = RM67120_G244.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G244.Value = RM67120_G244.Value - step_l;
                                    else RM67120_G244.Value = RM67120_G244.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B244.Value = RM67120_B244.Value - step_h;
                                    else RM67120_B244.Value = RM67120_B244.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B244.Value = RM67120_B244.Value - step_l;
                                    else RM67120_B244.Value = RM67120_B244.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 6:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R240.Value = RM67120_R240.Value - step_h;
                                    else RM67120_R240.Value = RM67120_R240.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R240.Value = RM67120_R240.Value - step_l;
                                    else RM67120_R240.Value = RM67120_R240.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G240.Value = RM67120_G240.Value - step_h;
                                    else RM67120_G240.Value = RM67120_G240.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G240.Value = RM67120_G240.Value - step_l;
                                    else RM67120_G240.Value = RM67120_G240.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B240.Value = RM67120_B240.Value - step_h;
                                    else RM67120_B240.Value = RM67120_B240.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B240.Value = RM67120_B240.Value - step_l;
                                    else RM67120_B240.Value = RM67120_B240.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 7:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R232.Value = RM67120_R232.Value - step_h;
                                    else RM67120_R232.Value = RM67120_R232.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R232.Value = RM67120_R232.Value - step_l;
                                    else RM67120_R232.Value = RM67120_R232.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G232.Value = RM67120_G232.Value - step_h;
                                    else RM67120_G232.Value = RM67120_G232.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G232.Value = RM67120_G232.Value - step_l;
                                    else RM67120_G232.Value = RM67120_G232.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B232.Value = RM67120_B232.Value - step_h;
                                    else RM67120_B232.Value = RM67120_B232.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B232.Value = RM67120_B232.Value - step_l;
                                    else RM67120_B232.Value = RM67120_B232.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 8:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R224.Value = RM67120_R224.Value - step_h;
                                    else RM67120_R224.Value = RM67120_R224.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R224.Value = RM67120_R224.Value - step_l;
                                    else RM67120_R224.Value = RM67120_R224.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G224.Value = RM67120_G224.Value - step_h;
                                    else RM67120_G224.Value = RM67120_G224.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G224.Value = RM67120_G224.Value - step_l;
                                    else RM67120_G224.Value = RM67120_G224.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B224.Value = RM67120_B224.Value - step_h;
                                    else RM67120_B224.Value = RM67120_B224.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B224.Value = RM67120_B224.Value - step_l;
                                    else RM67120_B224.Value = RM67120_B224.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 9:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R208.Value = RM67120_R208.Value - step_h;
                                    else RM67120_R208.Value = RM67120_R208.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R208.Value = RM67120_R208.Value - step_l;
                                    else RM67120_R208.Value = RM67120_R208.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G208.Value = RM67120_G208.Value - step_h;
                                    else RM67120_G208.Value = RM67120_G208.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G208.Value = RM67120_G208.Value - step_l;
                                    else RM67120_G208.Value = RM67120_G208.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B208.Value = RM67120_B208.Value - step_h;
                                    else RM67120_B208.Value = RM67120_B208.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B208.Value = RM67120_B208.Value - step_l;
                                    else RM67120_B208.Value = RM67120_B208.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 10:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R192.Value = RM67120_R192.Value - step_h;
                                    else RM67120_R192.Value = RM67120_R192.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R192.Value = RM67120_R192.Value - step_l;
                                    else RM67120_R192.Value = RM67120_R192.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G192.Value = RM67120_G192.Value - step_h;
                                    else RM67120_G192.Value = RM67120_G192.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G192.Value = RM67120_G192.Value - step_l;
                                    else RM67120_G192.Value = RM67120_G192.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B192.Value = RM67120_B192.Value - step_h;
                                    else RM67120_B192.Value = RM67120_B192.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B192.Value = RM67120_B192.Value - step_l;
                                    else RM67120_B192.Value = RM67120_B192.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 11:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R160.Value = RM67120_R160.Value - step_h;
                                    else RM67120_R160.Value = RM67120_R160.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R160.Value = RM67120_R160.Value - step_l;
                                    else RM67120_R160.Value = RM67120_R160.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G160.Value = RM67120_G160.Value - step_h;
                                    else RM67120_G160.Value = RM67120_G160.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G160.Value = RM67120_G160.Value - step_l;
                                    else RM67120_G160.Value = RM67120_G160.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B160.Value = RM67120_B160.Value - step_h;
                                    else RM67120_B160.Value = RM67120_B160.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B160.Value = RM67120_B160.Value - step_l;
                                    else RM67120_B160.Value = RM67120_B160.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;

                    case 12:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R128.Value = RM67120_R128.Value - step_h;
                                    else RM67120_R128.Value = RM67120_R128.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R128.Value = RM67120_R128.Value - step_l;
                                    else RM67120_R128.Value = RM67120_R128.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G128.Value = RM67120_G128.Value - step_h;
                                    else RM67120_G128.Value = RM67120_G128.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G128.Value = RM67120_G128.Value - step_l;
                                    else RM67120_G128.Value = RM67120_G128.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B128.Value = RM67120_B128.Value - step_h;
                                    else RM67120_B128.Value = RM67120_B128.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B128.Value = RM67120_B128.Value - step_l;
                                    else RM67120_B128.Value = RM67120_B128.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 13:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R127.Value = RM67120_R127.Value - step_h;
                                    else RM67120_R127.Value = RM67120_R127.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R127.Value = RM67120_R127.Value - step_l;
                                    else RM67120_R127.Value = RM67120_R127.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G127.Value = RM67120_G127.Value - step_h;
                                    else RM67120_G127.Value = RM67120_G127.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G127.Value = RM67120_G127.Value - step_l;
                                    else RM67120_G127.Value = RM67120_G127.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B127.Value = RM67120_B127.Value - step_h;
                                    else RM67120_B127.Value = RM67120_B127.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B127.Value = RM67120_B127.Value - step_l;
                                    else RM67120_B127.Value = RM67120_B127.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 14:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R95.Value = RM67120_R95.Value - step_h;
                                    else RM67120_R95.Value = RM67120_R95.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R95.Value = RM67120_R95.Value - step_l;
                                    else RM67120_R95.Value = RM67120_R95.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G95.Value = RM67120_G95.Value - step_h;
                                    else RM67120_G95.Value = RM67120_G95.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G95.Value = RM67120_G95.Value - step_l;
                                    else RM67120_G95.Value = RM67120_G95.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B95.Value = RM67120_B95.Value - step_h;
                                    else RM67120_B95.Value = RM67120_B95.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B95.Value = RM67120_B95.Value - step_l;
                                    else RM67120_B95.Value = RM67120_B95.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 15:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R63.Value = RM67120_R63.Value - step_h;
                                    else RM67120_R63.Value = RM67120_R63.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R63.Value = RM67120_R63.Value - step_l;
                                    else RM67120_R63.Value = RM67120_R63.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G63.Value = RM67120_G63.Value - step_h;
                                    else RM67120_G63.Value = RM67120_G63.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G63.Value = RM67120_G63.Value - step_l;
                                    else RM67120_G63.Value = RM67120_G63.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B63.Value = RM67120_B63.Value - step_h;
                                    else RM67120_B63.Value = RM67120_B63.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B63.Value = RM67120_B63.Value - step_l;
                                    else RM67120_B63.Value = RM67120_B63.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 16:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R47.Value = RM67120_R47.Value - step_h;
                                    else RM67120_R47.Value = RM67120_R47.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R47.Value = RM67120_R47.Value - step_l;
                                    else RM67120_R47.Value = RM67120_R47.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G47.Value = RM67120_G47.Value - step_h;
                                    else RM67120_G47.Value = RM67120_G47.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G47.Value = RM67120_G47.Value - step_l;
                                    else RM67120_G47.Value = RM67120_G47.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B47.Value = RM67120_B47.Value - step_h;
                                    else RM67120_B47.Value = RM67120_B47.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B47.Value = RM67120_B47.Value - step_l;
                                    else RM67120_B47.Value = RM67120_B47.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 17:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R31.Value = RM67120_R31.Value - step_h;
                                    else RM67120_R31.Value = RM67120_R31.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R31.Value = RM67120_R31.Value - step_l;
                                    else RM67120_R31.Value = RM67120_R31.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G31.Value = RM67120_G31.Value - step_h;
                                    else RM67120_G31.Value = RM67120_G31.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G31.Value = RM67120_G31.Value - step_l;
                                    else RM67120_G31.Value = RM67120_G31.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B31.Value = RM67120_B31.Value - step_h;
                                    else RM67120_B31.Value = RM67120_B31.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B31.Value = RM67120_B31.Value - step_l;
                                    else RM67120_B31.Value = RM67120_B31.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 18:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R23.Value = RM67120_R23.Value - step_h;
                                    else RM67120_R23.Value = RM67120_R23.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R23.Value = RM67120_R23.Value - step_l;
                                    else RM67120_R23.Value = RM67120_R23.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G23.Value = RM67120_G23.Value - step_h;
                                    else RM67120_G23.Value = RM67120_G23.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G23.Value = RM67120_G23.Value - step_l;
                                    else RM67120_G23.Value = RM67120_G23.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B23.Value = RM67120_B23.Value - step_h;
                                    else RM67120_B23.Value = RM67120_B23.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B23.Value = RM67120_B23.Value - step_l;
                                    else RM67120_B23.Value = RM67120_B23.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 19:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R15.Value = RM67120_R15.Value - step_h;
                                    else RM67120_R15.Value = RM67120_R15.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R15.Value = RM67120_R15.Value - step_l;
                                    else RM67120_R15.Value = RM67120_R15.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G15.Value = RM67120_G15.Value - step_h;
                                    else RM67120_G15.Value = RM67120_G15.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G15.Value = RM67120_G15.Value - step_l;
                                    else RM67120_G15.Value = RM67120_G15.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B15.Value = RM67120_B15.Value - step_h;
                                    else RM67120_B15.Value = RM67120_B15.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B15.Value = RM67120_B15.Value - step_l;
                                    else RM67120_B15.Value = RM67120_B15.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 20:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R11.Value = RM67120_R11.Value - step_h;
                                    else RM67120_R11.Value = RM67120_R11.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R11.Value = RM67120_R11.Value - step_l;
                                    else RM67120_R11.Value = RM67120_R11.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G11.Value = RM67120_G11.Value - step_h;
                                    else RM67120_G11.Value = RM67120_G11.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G11.Value = RM67120_G11.Value - step_l;
                                    else RM67120_G11.Value = RM67120_G11.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B11.Value = RM67120_B11.Value - step_h;
                                    else RM67120_B11.Value = RM67120_B11.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B11.Value = RM67120_B11.Value - step_l;
                                    else RM67120_B11.Value = RM67120_B11.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 21://10阶以下只进行亮度调节
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R7.Value = RM67120_R7.Value - step_h;
                                    else RM67120_R7.Value = RM67120_R7.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R7.Value = RM67120_R7.Value - step_l;
                                    else RM67120_R7.Value = RM67120_R7.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G7.Value = RM67120_G7.Value - step_h;
                                    else RM67120_G7.Value = RM67120_G7.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G7.Value = RM67120_G7.Value - step_l;
                                    else RM67120_G7.Value = RM67120_G7.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B7.Value = RM67120_B7.Value - step_h;
                                    else RM67120_B7.Value = RM67120_B7.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B7.Value = RM67120_B7.Value - step_l;
                                    else RM67120_B7.Value = RM67120_B7.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 22:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R5.Value = RM67120_R5.Value - step_h;
                                    else RM67120_R5.Value = RM67120_R5.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R5.Value = RM67120_R5.Value - step_l;
                                    else RM67120_R5.Value = RM67120_R5.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G5.Value = RM67120_G5.Value - step_h;
                                    else RM67120_G5.Value = RM67120_G5.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G5.Value = RM67120_G5.Value - step_l;
                                    else RM67120_G5.Value = RM67120_G5.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B5.Value = RM67120_B5.Value - step_h;
                                    else RM67120_B5.Value = RM67120_B5.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B5.Value = RM67120_B5.Value - step_l;
                                    else RM67120_B5.Value = RM67120_B5.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 23:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R3.Value = RM67120_R3.Value - step_h;
                                    else RM67120_R3.Value = RM67120_R3.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R3.Value = RM67120_R3.Value - step_l;
                                    else RM67120_R3.Value = RM67120_R3.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G3.Value = RM67120_G3.Value - step_h;
                                    else RM67120_G3.Value = RM67120_G3.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G3.Value = RM67120_G3.Value - step_l;
                                    else RM67120_G3.Value = RM67120_G3.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B3.Value = RM67120_B3.Value - step_h;
                                    else RM67120_B3.Value = RM67120_B3.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B3.Value = RM67120_B3.Value - step_l;
                                    else RM67120_B3.Value = RM67120_B3.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 24:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R1.Value = RM67120_R1.Value - step_h;
                                    else RM67120_R1.Value = RM67120_R1.Value + step_h;
                                    adjust_Rnum = 0;
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        RM67120_R1.Value = RM67120_R1.Value - step_l;
                                    else RM67120_R1.Value = RM67120_R1.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G1.Value = RM67120_G1.Value - step_h;
                                    else RM67120_G1.Value = RM67120_G1.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        RM67120_G1.Value = RM67120_G1.Value - step_l;
                                    else RM67120_G1.Value = RM67120_G1.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            else if (flag1 == 0)
                            {
                                flag2 = 0;
                                flag3 = 0;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B1.Value = RM67120_B1.Value - step_h;
                                    else RM67120_B1.Value = RM67120_B1.Value + step_h;
                                    adjust_Bnum = 0;
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        RM67120_B1.Value = RM67120_B1.Value - step_l;
                                    else RM67120_B1.Value = RM67120_B1.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                }
                RM67120_GAMMA_Click(RM67120_GammaW_Red, e);//调用寄存器写函数，把255阶R-gamma写入寄存器中。
                RM67120_GAMMA_Click(RM67120_GammaW_Green, e);//调用寄存器写函数，把255阶G-gamma写入寄存器中。
                RM67120_GAMMA_Click(RM67120_GammaW_Blue, e);//调用寄存器写函数，把255阶B-gamma写入寄存器中。
            }
        }
        private void RM67120_Gamma_Load(object sender, EventArgs e)
        {

        }
    }
}
